keep cvrnrA aar
duplicates drop
expand 7
bysort cvrnrA aar: gen d_yr = _n - 4
gen aarA = aar + d_yr
gen p = (d_yr>0)

merge m:1 cvrnrA aarA using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_com_all_cvrnr.dta", keep(match master) keepusing(nprod_vars vrdA_vars) nogen

merge m:1 cvrnrA aarA using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_vars_dom_all_cvrnr_dro.dta", keep(match master) keepusing(nprod vrdA) nogen
rename vrdA_dom_dro vrdA_dom
rename nprod_dro nprod_dom

merge m:1 cvrnrA aarA using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_exports_all_cvrnr.dta", keep(match master) keepusing(nprod nmark vrdA) nogen	
rename vrdA vrdA_exp
rename nprod nprod_exp
rename nmark nmark_exp

rename cvrnrA cvrnr
rename aar aar_ori
rename aarA aar
merge m:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_firm_subset1865.dta", keep(match) keepusing(employee_cvrnr) nogen
rename cvrnr cvrnrA
rename aar aarA
rename aar_ori aar

*In any year
gen multiproduct_vars = (nprod_vars>1)
replace multiproduct_vars = . if nprod_vars==.

*In any year
gen multiproduct_dom = (nprod_dom>1)
replace multiproduct_dom = . if nprod_dom==.

*In any year, conditional on exporting
gen multiproduct_exp_con = (nprod_exp>1)
replace multiproduct_exp_con = . if nprod_exp==.

*In any year
gen multiproduct_exp = (nprod_exp>1)
replace multiproduct_exp = 0 if nprod_exp==.

*Replace missing with zeros
gen nprod_exp0 = nprod_exp
replace nprod_exp0 = 0 if nprod_exp==.

*In year of merger
gen nprod_vars_aar = nprod_vars if aar==aarA
gen nprod_dom_aar = nprod_dom if aar==aarA
gen nprod_exp_aar = nprod_exp if aar==aarA

collapse (mean) nprod_vars nprod_dom nprod_exp nprod_exp0 nmark_exp vrdA_vars vrdA_dom vrdA_exp employee_cvrnr nprod_vars_aar nprod_dom_aar nprod_exp_aar (max) multiproduct_vars multiproduct_dom multiproduct_exp multiproduct_exp_con, by(cvrnrA aar p)

gen exporter = (nprod_exp>0 & nprod_exp!=.)

*Same as multiproduct_dom
gen multiproduct_vars_avg = (nprod_vars>1)
replace multiproduct_vars_avg = . if nprod_vars==.

*Same as multiproduct_dom
gen multiproduct_dom_avg = (nprod_dom>1)
replace multiproduct_dom_avg = . if nprod_dom==.

*Different from multiproduct_exp
gen multiproduct_exp_avg = (nprod_exp0>1)

*Same as multiproduct_exp_con
gen multiproduct_exp_con_avg = (nprod_exp>1)
replace multiproduct_exp_con_avg = . if nprod_exp==.

gen exporter_aar = (nprod_exp_aar>0 & nprod_exp_aar!=.)

gen nprod_vars5 = (nprod_vars>=5 & nprod_vars!=.)
gen nprod_dom5 = (nprod_dom>=5 & nprod_dom!=.)
gen nprod_exp5 = (nprod_exp>=5 & nprod_exp!=.)

*Acquirers
* Fact 1
*Share of multiproduct firms on ALL markets
*tab multiproduct_vars if p==0
sum multiproduct_vars if p==0
post stats ("Fact 1") ("Acquirers") ("Multiproduct") (r(N)) (r(mean)) (r(sd))

*Same
tab multiproduct_vars_avg if p==0

*Share of firms with 5 or more products on ALL markets
sum nprod_vars5 if p==0 & nprod_vars>0 & nprod_vars!=.
post stats ("Fact 1") ("Acquirers") ("5 or more") (r(N)) (r(mean)) (r(sd))

* Fact 1 supplement
*Share of multiproduct firms on export market, based on avg # products
tab multiproduct_exp_avg if p==0
*Share of multiproduct firms on export market conditional on exporting
tab multiproduct_exp_con if p==0

* Fact 4
*Share of exporters
*tab exporter if p==0
sum exporter if p==0
post stats ("Fact 4") ("Acquirers") ("Exporter pre") (r(N)) (r(mean)) (r(sd))
*tab exporter if p==1
sum exporter if p==1
post stats ("Fact 4") ("Acquirers") ("Exporter post") (r(N)) (r(mean)) (r(sd))

gen temp0 = nprod_exp if p==0
egen mtemp0 = mean(temp0), by(cvrnrA aar)
gen temp1 = nprod_exp if p==1
egen mtemp1 = mean(temp1), by(cvrnrA aar)

*Number of markets on export market pre-merger conditional on exporting both pre and post-merger
sum nmark_exp if mtemp0!=. & mtemp1!=. & p==0
post stats ("Fact 4") ("Acquirers") ("Markets pre") (r(N)) (r(mean)) (r(sd))
*Number of markets on export market post-merger conditional on exporting both pre and post-merger
sum nmark_exp if mtemp0!=. & mtemp1!=. & p==1
post stats ("Fact 4") ("Acquirers") ("Markets post") (r(N)) (r(mean)) (r(sd))

*Number of products on export market pre-merger conditional on exporting both pre and post-merger
sum nprod_exp if mtemp0!=. & mtemp1!=. & p==0
post stats ("Fact 4") ("Acquirers") ("Products pre") (r(N)) (r(mean)) (r(sd))
*Number of products on export market post-merger conditional on exporting both pre and post-merger
sum nprod_exp if mtemp0!=. & mtemp1!=. & p==1
post stats ("Fact 4") ("Acquirers") ("Products post") (r(N)) (r(mean)) (r(sd))